#include "MemoryPool.h"

//1024 1KB
//1024x1024 1MB 1048576
//1024x1024x1024 1GB 1073741824

void*operator new(std::size_t size) {
	size_t alloc_size = ALICE_ADJUST_MEMORY_SIZE(size);
	void* ptr = malloc(alloc_size);
	return ptr;
}

void*operator new(std::size_t size, MemoryLabel memID){
#if USE_POOL
	if (memID==kMemEditorId){
		void*ptr = malloc(size);
		return ptr;
	}
	void*ptr = GetMemory(size);
	Alice::Profiler::OnNewObject(ptr, memID);
	return ptr;
#else
	size_t alloc_size = ALICE_ADJUST_MEMORY_SIZE(size);
	void* ptr = malloc(alloc_size);
	return ptr;
#endif
}

void*operator new[](std::size_t size, MemoryLabel memID){
#if USE_POOL
	if (memID == kMemEditorId){
		void*ptr = malloc(size);
		return ptr;
	}
	void*ptr = GetMemory(size);
	Alice::Profiler::OnNewObject(ptr, memID);
	return ptr;
#else
	size_t alloc_size = ALICE_ADJUST_MEMORY_SIZE(size);
	void* ptr = malloc(alloc_size);
	return ptr;
#endif
}

void operator delete(void*ptr,MemoryLabel memID){
	//Error("un implemented method");
}

void operator delete[](void*ptr, MemoryLabel memID){
	//Error("un implemented method");
}
#if ALICE_ANDROID
void operator delete(void*ptr)noexcept(true){
	Recycle(ptr);
}

void operator delete [](void*ptr)noexcept(true){
	Recycle(ptr);
}
#else
void operator delete(void*ptr){
	free(ptr);
}

void operator delete [](void*ptr){
	free(ptr);
}
#endif
